/*************************************************************************
	> File Name: oj-548_合唱队形.cpp
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2021年02月07日 星期日 16时16分49秒
 ************************************************************************/
#include <iostream>
using namespace std;
#define MAX_N 1000

int n, h[MAX_N + 5], dp[MAX_N + 5][3];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
        dp[i][0] = dp[i][1] = 1;
    }
    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j < i; ++j) {
            if (h[j] < h[i]) {
                //cout << "h[" << j << "] < h[" << i << "]\n";
                //cout << "dp[" << i << "][0] = " << dp[i][0] << endl;
                //cout << "dp[" << j << "][0] + 1 = " << dp[j][0] + 1 << endl;
                dp[i][0] = max(dp[i][0], dp[j][0] + 1);
            }
        } /* dp[i][0] 表示以第i个人为分界，前面有几个人比他矮*/
    }
    for (int i = n - 1; i >= 1; --i) {
        for (int j = n; j > i; --j) {
            if (h[j] < h[i]) {
                dp[i][1] = max(dp[i][1], dp[j][1] + 1);
            }
        } /* dp[i][0] 表示以第i个人为分界，后面有几个人比他矮*/
    }
    int ans = 0x3f3f3f3f;
    for (int i = 1; i <= n; ++i) {
        dp[i][2] = dp[i][0] + dp[i][1] - 1; //以i为界，有多少个人满足队形
        ans = min(ans, n - dp[i][2]); //更新最小值
    }
    cout << ans << endl;
    return 0;
}
